<template>
  <el-dialog
    v-loading="loading"
    :visible.sync="dialog"
    title="下载"
    width="450px"
    :close-on-click-modal="false"
    append-to-body
    @close="cancel"
  >
    <div>
      <el-form ref="editForm" :model="entity" :rules="rules" label-width="auto" :inline="true" size="mini">
        <el-row>
          <el-col :span="24">
            <el-form-item label="采购ID:" prop="buyerId">
              <el-select v-model="entity.buyerId" size="mini" style="width: 280px;">
                <el-option v-for="bid in parent.buyerIds" :key="bid" :label="bid" :value="bid" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" size="mini" round @click="cancel">取消</el-button>
      <el-button type="primary" size="mini" round @click="doSubmit">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
// import { Message } from 'element-ui'
import { doDownload } from '@/api/olm/download'

const tipMsg = '请选择采购'
export default {
  props: {
    parent: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      dialog: false,
      loading: false,
      entity: this.emptyEntity(),
      rules: {
        buyerId: [{ required: true, message: tipMsg, trigger: 'blur' }, { required: true, message: tipMsg, trigger: 'change' }]
      }
    }
  },
  methods: {
    emptyEntity() {
      return {
        buyerId: null,
        scheduleId: null
      }
    },
    cancel() {
      this.dialog = false
      this.entity = this.emptyEntity()
    },
    // 确定按钮触发
    doSubmit() {
      this.$refs.editForm.validate(valid => {
        if (valid) {
          this.$confirm('确认下载？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.loading = true
            var data = this.entity
            doDownload('/olm-excel/excel/exportOlmListData', data, '清单文件.xlsx')
            this.loading = false
            this.dialog = false
            this.entity = this.emptyEntity()
          })
        }
      })
    }
  }
}
</script>
